﻿using System.Collections;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using RazakiBLL.Entities;

namespace RazakiBLL.Managers
{
    public class WorkRps : RpsRazaki<Work>
    {
        public WorkRps(ObjectContext context)
            : base(context)
        {
        }

        /// <summary>
        /// کل آیتم ها را در گروه های شش تایی بر می گرداند
        /// </summary>
        /// <returns></returns>
        public Dictionary<short, List<Work>> GetAllInSixItemsGroups()
        {
            var works = UtilitiesBLL.CacheProvider.GetData<List<Work>>("Works");
            if (works == null)
            {
                works = base.GetAll().OrderBy(x => x.Priority).ToList();
                UtilitiesBLL.CacheProvider.SetData("Works", works);
            }

            Dictionary<short, List<Work>> groups = new Dictionary<short, List<Work>>();

            for (short i = 1; i <= (works.Count / 6); i++)
            {
                var query = from w in works where (((i - 1) * 6 + 1) <= w.Priority) && (w.Priority <= (i * 6)) select w;

                groups[(short)(i - 1)] = query.ToList();
            }

            return groups;
        }

    }
}
